﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using GDIImage = System.Drawing.Image;
using GDIBitmap = System.Drawing.Bitmap;
using Microsoft.Xna.Framework.Graphics;

namespace XRpgLibrary.ExtensionMethods
{
    public static class Texture2DExtension
    {

        public static System.Drawing.Image ToImage(this Texture2D texture)
        {
            GDIImage image;

            using (MemoryStream ms = new MemoryStream())
            {
                texture.SaveAsPng(ms, texture.Width, texture.Height);

                ms.Seek(0, SeekOrigin.Begin);

                image = GDIBitmap.FromStream(ms);
            }

            return image;
        }
    }
}
